# @time     :2022/1/16
# @Author   :Simple
# @FileName :main_page
import os

from common.element import GetElement
import yaml
from xueqiu_demo.page.base_page import BasePage as base
from xueqiu_demo.page.market_page import MarketPage as market
from xueqiu_demo.page.trade_page import TradePage as trade


class MainPage(base):
    """
    首页
    """
    tv_search = GetElement(id_="com.xueqiu.android:id/tv_search", describe="搜索", wait=True)
    search_input = GetElement(id_="com.xueqiu.android:id/search_input_text", describe="编辑搜索内容")
    first_search = GetElement(id_="com.xueqiu.android:id/name", describe="搜索结果第一个")
    stock_tab = GetElement(xpath="//*[@text='股票']", describe="股票tab")
    stock_name = GetElement(id_="com.xueqiu.android:id/stockName", describe="股票名称")
    price_btn = GetElement(id_="com.xueqiu.android:id/current_price", describe="股票现价")
    cancel_btn = GetElement(xpath="//*[@text='取消']", describe="取消按钮")
    trade_btn = GetElement(xpath="//*[@text='交易']", describe="交易", wait=True)
    main_btn = GetElement(xpath="//*[@text='雪球']", describe="雪球", wait=True)
    market_btn = GetElement(xpath='//*[@text="行情"]', describe="行情", wait=True)

    def goto_market(self):
        # 进入'行情'页
        self.market_btn.click()
        return market(self.driver)

    def goto_trade(self):
        # 进入'交易'页
        self.trade_btn.click()
        return trade(self.driver)

